package work02;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Test02 {
    public static void main(String[] args) {
        BufferedReader br = null;
        Map<String,String> map = new HashMap<String,String>();
        try{
            FileInputStream fis = new FileInputStream("C:\\Users\\郝国宾\\IdeaProjects\\0412\\File和输入输出流作业\\src\\work01\\worldCup");
            InputStreamReader isr = new InputStreamReader(fis);//创建一个桥转换流
            br = new BufferedReader(isr);//字符过滤流
            String s;
            while ((s = br.readLine()) !=null){
                String[] ss = s.split("/");//把存入的信息做字符串拆分成年份和国家
                map.put(ss[0],ss[1]);//把国家和年份分别放入集合
            }
        }catch (Exception e){
            e.getStackTrace();
        }finally {
            {
                if (br != null){
                    try {
                        br.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入要查询世界杯的年份：");
            String year = sc.nextLine();
            if (map.containsKey(year) == false){
                System.out.println("没有举办世界杯！");
            }else {
                System.out.println("该年的世界冠军是：" + map.get(year));
            }
        }
    }
}
